package OrdersSystem;

import static org.junit.Assert.*;

import java.sql.Time;
import java.util.Calendar;
import java.util.Date;

import org.junit.Test;

import DBSystem.DataBase;

public class CustomerTest {
	DataBase db = new DataBase();

	@Test
	public void testSubmitSingleOrder() {
		
		// create a customer
		ContactDetails contact = new ContactDetails("Marchmont", "1F1", "Edinburgh", "EH9 1BM",
				"0798993454", "customer1@sms.ed.ac.uk");
		Customer testCustomer = new Customer(111, "Eddie", "Murphy", contact, 0);
		db.storeUser(testCustomer);
		
		

		
		
		// Intergration Test Case #15 Incorrect Date >7 days
		System.out.println("Integration Test Case #15: Order with incorrect date (>7 days). Should not validate");
		Calendar c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 8);
		Date requestedDeliveryDate = c.getTime();
		Time requestedDeliveryTime = new Time(100);
		String testResult = testCustomer.submitSingleOrder("Edinburgh", requestedDeliveryDate, requestedDeliveryTime, 1, 10, "" );
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("incorrect parameters!"));
		
		//Integration Test Case #16 Incorrect quantity 1.25
		System.out.println("Integration Test Case #16: Order with incorrect quantity (1.25). Should not validate");
		c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 3);
		requestedDeliveryDate = c.getTime();
		testResult = testCustomer.submitSingleOrder("Edinburgh", requestedDeliveryDate, requestedDeliveryTime, 1, (float) 1.25, "" );
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result",true, testResult.contains("incorrect parameters!"));
		
		//Integration Test Case #17 Incorrect Date <24h
		System.out.println("Integration Test Case #17: Order with incorrect date (<24h). Should not validate");
		requestedDeliveryDate = new Date();
		testResult = testCustomer.submitSingleOrder("Edinburgh",requestedDeliveryDate, requestedDeliveryTime, 1, 10, "" );
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("incorrect parameters!"));
		
		//Integration Test Case #18 Date <24 and quantity 1.25
		System.out.println("Integration Test Case #18: Order with incorrect date (<24h) and quantity (1.25). Should not validate");
		c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 8);
		requestedDeliveryDate = c.getTime();
		testResult = testCustomer.submitSingleOrder("Edinburgh", requestedDeliveryDate, requestedDeliveryTime, 1, (float)1.25, "" );
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("incorrect parameters!"));


	
		// Test Case #19 Correct Data in the order, order should not validate.
		System.out.println("Integration Test Case #19: Correct order (but with an odd orderID (See DeliveriesComm java doc for more info) Should not validate");
		c = Calendar.getInstance();
		c.setTime(new Date());
		c.add(Calendar.DATE, 3);
		requestedDeliveryDate = c.getTime();		
		requestedDeliveryTime = new Time(100);
		testResult = testCustomer.submitSingleOrder("Edinburgh", requestedDeliveryDate, requestedDeliveryTime, 1, 8, "" );
		System.out.println("TEST RESULT: " + testResult);
		System.out.println();
		assertEquals("Result", true, testResult.contains("apologise"));
		
	
	}

}
